using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace KFGame.Modes
{

    [System.Serializable]
    public class KFSPTOEConfigMode: KFMode
    {
       

        public static KFSPTOEConfigMode getModes()
        {
              if (!editObject)   
              editObject = new GameObject("KF_Config_edit");
            var mode = editObject.AddComponent<KFSPTOEConfigMode>();
            return mode;
        }
        

        public string filename = "kfseralporteventstofkevent.ini";


        /// <summary>
        /// 所有事件
        /// </summary>
        /// <typeparam name="KFKeyEventMode"></typeparam>
        /// <returns></returns>
        [SerializeField]
        [Tooltip("IO接口记录集")]
        public List<KFSPTOEMode> eventModes = new List<KFSPTOEMode>();

        public override string FileName()
        {
            return filename;
        }

        public override void save()
        {
            string iniPath = Application.streamingAssetsPath + "/KFConfig/" + filename;
            INIParser iNIParser = new INIParser();
            iNIParser.Open(iniPath);
            iNIParser.clean();

            for (var i = 0; i < eventModes.Count; i++)
            {
                if (eventModes[i].modeName == null)
                    eventModes[i].modeName = eventModes[i].name + i;

                iNIParser.WriteValue(eventModes[i].modeName, "enter", eventModes[i].enter);
                iNIParser.WriteValue(eventModes[i].modeName, "name", eventModes[i].name);

                iNIParser.WriteValue(eventModes[i].modeName, "fromevent", eventModes[i].fromevent);
                iNIParser.WriteValue(eventModes[i].modeName, "toevent", eventModes[i].toevent);
                iNIParser.WriteValue(eventModes[i].modeName, "type", eventModes[i].type);
                iNIParser.WriteValue(eventModes[i].modeName, "tag", eventModes[i].tag); 
                iNIParser.WriteValue(eventModes[i].modeName, "des", eventModes[i].des);


            }
            iNIParser.save();

        }

        public override void LoadDatas()
        {
            string iniPath = Application.streamingAssetsPath + "/KFConfig/" + filename;
            INIParser iNIParser = new INIParser();
            iNIParser.Open(iniPath);
            foreach (var item in iNIParser.SectionNames())
            {
                KFSPTOEMode mode = new KFSPTOEMode();
                mode.modeName = item;

                mode.enter = iNIParser.ReadValue(item, "enter", true);
                mode.name = iNIParser.ReadValue(item, "name", "");
                mode.fromevent = iNIParser.ReadValue(item, "fromevent", "");
                mode.toevent = iNIParser.ReadValue(item, "toevent", "");
                mode.type = iNIParser.ReadValue(item, "type", "");
                mode.tag = iNIParser.ReadValue(item, "tag", "");
                
                mode.des = iNIParser.ReadValue(item, "des", "");
                eventModes.Add(mode);



            }
        }
    }
}